<?php
namespace Act\Os;
use Lib\ErrorMessage;
use Lib\Common;
class Groups extends Backend{
	public function doGet(){
		$this->display('index.php',array(
			'admin_action_confirm'=>Common::renderJsConfirm("icon-remove"),
			'groups'=>model('#UserGroup','adm_')->getAllGroup(),
		));
	}

	public function doDelete(){
		$group_id = get('group_id',0,'absint');
		$this->checkParam($group_id);
		$user_group_mod = model('#UserGroup','adm_');

		$users = $user_group_mod->getGroupUsers($group_id);
		if(sizeof($users)>0){
			return $this->error(ErrorMessage::HAVE_USER);
		}else if(intval($group_id) === 1){
			return $this->error(ErrorMessage::CAN_NOT_DO_FOR_SUPER_GROUP);
		}else{
			$group = $user_group_mod->getGroupById($group_id);
			$result = $user_group_mod->delGroup( $group_id );
			if ($result>0) {
				model('#SysLog','adm_')->addLog (session('user_info')['user_name'], 'DELETE', 'UserGroup',$group_id, json_encode($group) );
				$this->success ('已将账号组删除','os/groups');
			}else{
				$this->error("error",'os/groups');
			}
		}
	}
}